package 优先算法.双指针.成最多水的容器;

/**
 *https://leetcode.cn/problems/container-with-most-water/description/
 */
public class MaxWater {
    public static void main(String[] args) {
        Solution so = new Solution();
        int[] arr ={1,8,6,2,5,4,8,3,7};
        System.out.println(so.maxArea(arr));
    }
}
class Solution {
    public int maxArea(int[] height) {
        int left = 0,right = height.length-1;

        int Max = 0;

        while(left < right){
            int index = right - left;
            int h = Math.min(height[left], height[right]);
            int rel = index * h;
            Max=Math.max(Max, rel);
            if(height[left]<height[right]){
                left++;
            }else{
                right--;
            }
        }
        return Max;
    }
}